﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using ShareContent;
using AncientEmpires_025_132.ResourceString;

namespace AncientEmpires_025_132
{
    public class OptionPanel : VisibleGameEntity
    {
        // Tỷ lệ để vẽ panel
        private float _scale = 1f;
        public float Scale
        {
            get { return _scale; }
            set { _scale = value; }
        }

        // Vị trí của panel trong màn hình.
        private Vector2 _positionPanel;
        public Vector2 PositionPanel
        {
            get { return _positionPanel; }
            set { _positionPanel = value; }
        }

        private Vector2 _ScaleDimension;
        public Vector2 ScaleDimension
        {
            get { return _ScaleDimension; }
            set { _ScaleDimension = value; }
        }

        private Vector2 _sizePanel;
        public Vector2 SizePanel
        {
            get { return _sizePanel; }
            set { _sizePanel = value; }
        }
        private AuthenticationForm _Authentication;
        public AuthenticationForm Authentication
        {
            get { return _Authentication; }
            set { _Authentication = value; }
        }

        private PlayingMenu _playingMenu;

        public PlayingMenu PlayingMenu
        {
            get { return _playingMenu; }
            set { _playingMenu = value; }
        }

        #region Các text, button, minimap, avatar,... trong panel.
        // Button menu.
        private MyButton _btnMenu;
        public MyButton BtnMenu
        {
            get { return _btnMenu; }
            set { _btnMenu = value; }
        }

        // Button endturn
        private MyButton _btnEndturn;
        public MyButton BtnEndturn
        {
            get { return _btnEndturn; }
            set { _btnEndturn = value; }
        }

        // Button buy
        private MyButton _btnBuy;
        public MyButton BtnBuy
        {
            get { return _btnBuy; }
            set { _btnBuy = value; }
        }

        // MiniMap;
        private MiniMap _miniMapCurrent;
        public MiniMap MiniMapCurrent
        {
            get { return _miniMapCurrent; }
            set { _miniMapCurrent = value; }
        }

        // Nation name current.
        private string _nationCurrent;
        public string NationCurrent
        {
            get { return _nationCurrent; }
            set { _nationCurrent = value; }
        }

        // Time of a turn current.
        private string _turnTimeCurrent;
        public string TurnTimeCurrent
        {
            get { return _turnTimeCurrent; }
            set { _turnTimeCurrent = value; }
        }
        // Money of nation current.
        private string _moneyCurrent;
        public string MoneyCurrent
        {
            get { return _moneyCurrent; }
            set { _moneyCurrent = value; }
        }

        // Number of building current.
        private string _numBuildingCurrent;
        public string NumBuildingCurrent
        {
            get { return _numBuildingCurrent; }
            set { _numBuildingCurrent = value; }
        }
        // Unit cap of nation current.
        private string _numCharacterCurrent;
        public string NumCharacterCurrent
        {
            get { return _numCharacterCurrent; }
            set { _numCharacterCurrent = value; }
        }


        // Avatar character current is selected.
        private AvatarCharacter _avatarCurrentCharacter;
        public AvatarCharacter AvatarCurrentCharacter
        {
            get { return _avatarCurrentCharacter; }
            set { _avatarCurrentCharacter = value; }
        }

        // List avatar character can buy when click on castle.
        private List<AvatarCharacter> _listBuyAvatarCharater;
        public List<AvatarCharacter> ListBuyAvatarCharater
        {
            get { return _listBuyAvatarCharater; }
            set { _listBuyAvatarCharater = value; }
        }

        #endregion



        #region Vị trí các text trong panel
        // string team name
        public Vector2 PositionScaleStringNationName;

        // Position string time of a turn current.
        public Vector2 PositionScaleStringTurnTime;

        // Position string money of team
        public Vector2 PositionScaleStringMoney;

        // Position string numbers of characters
        public Vector2 PositionScaleStringNumCharacters;

        // Position string numbers of building
        public Vector2 PositionScaleStringNumBuildings;

        // Position string name of character is selected.
        public Vector2 PositionScaleCharacterName;

        // Position string damage of character is selected.
        public Vector2 PositionScaleCharacterDamage;

        // Position string defense of character is selected.
        public Vector2 PositionScaleCharacterDefense;

        // Position string health point of character is selected.
        public Vector2 PositionScaleCharacterHP;


        /////// Vị trí các text thông tin của character trong khung để mua.
        public Vector2 PositionScaleNameCharacterBuy;
        public Vector2 PositionScaleDamageCharacterBuy;
        public Vector2 PositionScaleDefenseCharacterBuy;
        public Vector2 PositionScaleMaxDistanceCharacterBuy;
        public Vector2 PositionScalePriceCharacterBuy;
        #endregion




        // Sự kiện update text trước khi vẽ các text về nationname, money,...
        public delegate void EventHandleUpdateText();
        public event EventHandleUpdateText EventUpdateText;

        // Sự kiện kết thúc 1 lượt đi của nation.
        public delegate void EventHandleEndturn();
        public event EventHandleEndturn EventEndturn;

        public delegate void EventHandleBuyCharacter(CharacterName characterName);
        public event EventHandleBuyCharacter EventBuy;

        public delegate void EventHandleBackMainMenu();
        public event EventHandleBackMainMenu EventBackMainMenu;

        public delegate void EventHandleExitGame();
        public event EventHandleExitGame EventExitGame;

        public delegate void EventHandlePauseGame();
        public event EventHandlePauseGame EventPauseGame;

        public delegate void EventHandleResumeGame();
        public event EventHandleResumeGame EventResumeGame;

        #region Xử lý các sự kiện
        //bool isAccept
        void Authentication_SelectOnForm(bool isAccept)
        {
            if (isAccept)
            {
                EventEndturn();
            }
        }

        public void SelectAvatarBuy(AvatarCharacter avtCharacter)
        {
            for (int i = 0; i < ListBuyAvatarCharater.Count; i++)
            {
                ListBuyAvatarCharater[i].IsSelected = false;
            }
            avtCharacter.IsSelected = true;
        }

        public void PlayingMenuSelect(int choice)
        {
            switch (choice)
            { 
                case 0:
                    EventResumeGame();
                    PlayingMenu.IsActive = false;
                    break;
                case 1:
                    EventBackMainMenu();
                    PlayingMenu.IsActive = false;
                    break;
                case 4:
                    EventExitGame();
                    break;
            }
        }
        #endregion


        public OptionPanel(ContentManager content, string[] strtexture, Vector2 position, Vector2 topleft, Vector2 size)
        {
            ScaleDimension = new Vector2(0.18f, 1f);
            ListSprites = new List<Sprite2D>();

            Texture2D[] texture = new Texture2D[strtexture.Length];
            for (int i = 0; i < strtexture.Length; i++)
            {
                texture[i] = content.Load<Texture2D>(strtexture[i]);
            }
            Sprite2D temp = new Sprite2D(texture, new Vector2(), new Vector2());
            temp.Size = size;
            temp.Position = position;
            temp.TopLeft = topleft;
            this.ListSprites.Add(temp); 
            this.SizePanel = size;
            this.PositionPanel = position;

            // Tạo form xác nhận khi click end turn(hết lượt đi của nation).
            InfoAuthenticationForm infoAuthentication = content.Load<InfoAuthenticationForm>(StringGame.StringXMLAuthenticationForm);
            Authentication = new AuthenticationForm(content, infoAuthentication);
            Authentication.SelectOnForm += new AuthenticationForm.EventHandlelect(Authentication_SelectOnForm);
        }
        
        public OptionPanel(ContentManager content, InfoOptionPanel info)
        {
            this.TurnTimeCurrent = "";
            this.PositionScaleStringTurnTime = info.PositionScaleTurnTime;
            this.PositionScaleStringMoney = info.PositionScaleStringMoney;
            this.PositionScaleStringNationName = info.PositionScaleStringNationName;
            this.PositionScaleStringNumBuildings = info.PositionScaleStringNumBuildings;
            this.PositionScaleStringNumCharacters = info.PositionScaleStringNumCharacters;

            this.PositionScaleCharacterName = info.PositionScaleCharacterName;
            this.PositionScaleCharacterDamage = info.PositionScaleCharacterDamage;
            this.PositionScaleCharacterDefense = info.PositionScaleCharacterDefense;
            this.PositionScaleCharacterHP = info.PositionScaleCharacterHP;

            this.PositionScaleNameCharacterBuy = info.PositionScaleNameCharacterBuy;
            this.PositionScalePriceCharacterBuy = info.PositionScalePriceCharacterBuy;
            this.PositionScaleDamageCharacterBuy = info.PositionScaleDamageCharacterBuy;
            this.PositionScaleDefenseCharacterBuy = info.PositionScaleDefenseCharacterBuy;
            this.PositionScaleMaxDistanceCharacterBuy = info.PositionScaleMaxDistanceCharacterBuy;

            ScaleDimension = new Vector2(0.2f, 1f);
            ListBuyAvatarCharater = new List<AvatarCharacter>();
            ListSprites = new List<Sprite2D>();

            Texture2D[] texture = new Texture2D[info.ListStringTexture.Count];
            for (int i = 0; i < info.ListStringTexture.Count; i++)
            {
                texture[i] = content.Load<Texture2D>(info.ListStringTexture[i]);
            }
            Sprite2D temp = new Sprite2D(texture, new Vector2(), new Vector2());
            temp.Size = info.Size;
            temp.Position = info.Position;
            temp.TopLeft = info.TopLeft;
            this.ListSprites.Add(temp);
            this.SizePanel = info.Size;
            this.PositionPanel = info.Position;

            InitBuyAvatarCharacter(content, info);

            // Tạo form xác nhận khi click end turn(hết lượt đi của nation).
            InfoAuthenticationForm infoAuthentication = content.Load<InfoAuthenticationForm>(StringGame.StringXMLAuthenticationForm);
            Authentication = new AuthenticationForm(content, infoAuthentication);
            Authentication.SelectOnForm +=new AuthenticationForm.EventHandlelect(Authentication_SelectOnForm);
            
            PlayingMenu = new PlayingMenu(content, "XML/PlayingMenuWithXML");
            PlayingMenu.MenuSelect += new PlayingMenu.EventHandleMenuSelect(PlayingMenuSelect);

            // Tạo các component cho panel.
            InitComponent(content, info);
        }

        public void InitBuyAvatarCharacter(ContentManager content, InfoOptionPanel info)
        {
            
            AvatarCharacter tempKing = new AvatarCharacter();
            tempKing.CharacterName = CharacterName.King.ToString();
            tempKing.PositionScale = info.PositionScaleKingCharacter;
            ListBuyAvatarCharater.Add(tempKing);
            

            AvatarCharacter tempCombative = new AvatarCharacter();
            tempCombative.CharacterName = CharacterName.Combative.ToString();
            tempCombative.PositionScale = info.PositionScaleCombativeCharacter;
            ListBuyAvatarCharater.Add(tempCombative);

            AvatarCharacter tempFairy = new AvatarCharacter();
            tempFairy.CharacterName = CharacterName.Fairy.ToString();
            tempFairy.PositionScale = info.PositionScaleFairyCharacter;
            ListBuyAvatarCharater.Add(tempFairy);

            AvatarCharacter tempHydra = new AvatarCharacter();
            tempHydra.CharacterName = CharacterName.Hydra.ToString();
            tempHydra.PositionScale = info.PositionScaleHydraCharacter;
            ListBuyAvatarCharater.Add(tempHydra);

            AvatarCharacter tempArcher = new AvatarCharacter();
            tempArcher.CharacterName = CharacterName.Archer.ToString();
            tempArcher.PositionScale = info.PositionScaleArcherCharacter;
            ListBuyAvatarCharater.Add(tempArcher);

            AvatarCharacter tempMage = new AvatarCharacter();
            tempMage.CharacterName = CharacterName.Mage.ToString();
            tempMage.PositionScale = info.PositionScaleMageCharacter;
            ListBuyAvatarCharater.Add(tempMage);

            AvatarCharacter tempCavalry = new AvatarCharacter();
            tempCavalry.CharacterName = CharacterName.Cavalry.ToString();
            tempCavalry.PositionScale = info.PositionScaleCavalryCharacter;
            ListBuyAvatarCharater.Add(tempCavalry);

            AvatarCharacter tempSoldier = new AvatarCharacter();
            tempSoldier.CharacterName = CharacterName.Soldier.ToString();
            tempSoldier.PositionScale = info.PositionScaleSoldierCharacter;
            ListBuyAvatarCharater.Add(tempSoldier);

            if(StringTextureCharacter.listCharacter == null)
                StringTextureCharacter.LoadContentTexture(content);
            foreach (ListSpritesCharacter character in StringTextureCharacter.listCharacter.listCharacters)
            {
                for (int i = 0; i < ListBuyAvatarCharater.Count; i++)
                {
                    if (ListBuyAvatarCharater[i].CharacterName == character.NameCharacter)
                    {
                        ListBuyAvatarCharater[i].TextureCurrent = content.Load<Texture2D>(character.StrTextureAvatar);
                        ListBuyAvatarCharater[i].Price = character.Pirce.ToString();
                        ListBuyAvatarCharater[i].MaxDistance = character.MaxDistance.ToString();
                        ListBuyAvatarCharater[i].Damage = character.MinDamage.ToString() + "-" + character.MaxDamage.ToString();
                        ListBuyAvatarCharater[i].Defense = character.Defense.ToString();
                        ListBuyAvatarCharater[i].IsHide = true;
                        ListBuyAvatarCharater[i].EventSelected += new AvatarCharacter.EventHandleSelected(SelectAvatarBuy);
                        break;
                    }
                }
            }
        }
        public void InitComponent(ContentManager content, InfoOptionPanel info)
        {
            // New button menu
            BtnMenu = new MyButton(content, info.ListStrTextureBtnMenu, new Vector2(), info.SizeBtnMenu, new Vector2());
            BtnMenu.PositionScale = info.PositionScaleBtnMenu;
            BtnMenu.ClickButton += new MyButton.EventHandleClick(BtnMenu_ClickButton);

            // New button endturn
            BtnEndturn = new MyButton(content, info.ListStrTextureBtnEndturn, new Vector2(), info.SizeBtnEndturn, new Vector2());
            BtnEndturn.PositionScale = info.PositionScaleBtnEndturn;
            BtnEndturn.ClickButton += new MyButton.EventHandleClick(BtnEndturn_ClickButton);

            // New Button buy
            BtnBuy = new MyButton(content, info.ListStrTextureBtnBuy, new Vector2(), info.SizeBtnBuy, new Vector2());
            BtnBuy.PositionScale = info.PositionScaleBtnbuy;
            BtnBuy.ClickButton += new MyButton.EventHandleClick(BtnBuy_ClickButton);
            
            // New Avatar character current is selected.
            AvatarCurrentCharacter = new AvatarCharacter();
            AvatarCurrentCharacter.PositionScale = info.PositionScaleAvatarCurrent;
            
        }

        // Xử lý sự kiện click button buy
        void BtnBuy_ClickButton()
        {
            for(int i = 0; i < ListBuyAvatarCharater.Count; i++)
            {
                if(ListBuyAvatarCharater[i].IsSelected)
                {
                    switch(ListBuyAvatarCharater[i].CharacterName)
                    {
                        case "King":
                            EventBuy(CharacterName.King);
                            break;
                        case "Combative":
                            EventBuy(CharacterName.Combative);
                            break;
                        case "Fairy":
                            EventBuy(CharacterName.Fairy);
                            break;
                        case "Hydra":
                            EventBuy(CharacterName.Hydra);
                            break;
                        case "Archer":
                            EventBuy(CharacterName.Archer);
                            break;
                        case "Mage":
                            EventBuy(CharacterName.Mage);
                            break;
                        case "Cavalry":
                            EventBuy(CharacterName.Cavalry);
                            break;
                        case "Soldier":
                            EventBuy(CharacterName.Soldier);
                            break;
                    }
                    return;
                }
            }
            
        }

        // Xử lý sự kiện khi click buttn endturn
        void BtnEndturn_ClickButton()
        {
            Authentication.IsShow = true;
            
        }

        // Xử lý sự kiện khi click buttn menu
        void BtnMenu_ClickButton()
        {
            EventPauseGame();
            PlayingMenu.IsActive = true;
        }

        
        public override void Update(GameTime gametime)
        {
            base.Update(gametime);
            BtnMenu.Update(gametime);
            BtnEndturn.Update(gametime);
            BtnBuy.Update(gametime);
            Authentication.Update(gametime);
            PlayingMenu.Update(gametime);
            for (int i = 0; i < ListBuyAvatarCharater.Count; i++)
            {
                ListBuyAvatarCharater[i].Update(gametime);
            }

            
        }
        public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            EventUpdateText();
            Vector2 SizeWindow = new Vector2(spriteBatch.GraphicsDevice.Viewport.Bounds.Width, 
                                             spriteBatch.GraphicsDevice.Viewport.Bounds.Height);

            Rectangle rectScale = new Rectangle(0,0,
                                                (int)(ScaleDimension.X * SizeWindow.X),
                                                (int)(ScaleDimension.Y * SizeWindow.Y)
                                                );

            for (int i = 0; i < ListSprites.Count; i++)
            {
                ListSprites[i].Size = new Vector2(rectScale.Width, rectScale.Height);
            }
            SizePanel = new Vector2(rectScale.Width, rectScale.Height);
            base.Draw(gameTime, spriteBatch);
            Authentication.Draw(gameTime, spriteBatch);
            PlayingMenu.Draw(gameTime,spriteBatch);

            Vector2 sizeTexturePanel = new Vector2(ListSprites[0].Textures[0].Bounds.Width, ListSprites[0].Textures[0].Bounds.Height);
            Vector2 scalesizepanel = new Vector2(SizePanel.X / sizeTexturePanel.X, SizePanel.Y / sizeTexturePanel.Y);

            DrawButton(gameTime, spriteBatch, scalesizepanel);
            
            // Draw string.
            DrawStringPanel(spriteBatch, scalesizepanel);

            // Draw avatar character is selected.
            DrawAvatarCharacter(gameTime, spriteBatch, scalesizepanel);

            DrawStringInfoCharacterToBuy(spriteBatch, scalesizepanel);
            
        }

        public Vector2 GetPositionInScale(Vector2 poscale)
        {
            return new Vector2(PositionPanel.X + poscale.X * SizePanel.X,
                               PositionPanel.Y + poscale.Y * SizePanel.Y
                                );
        }

        public void DrawButton(GameTime gameTime, SpriteBatch spriteBatch, Vector2 scalesizebtn)
        {
            //Vector2 sizeTexturePanel = new Vector2(ListSprites[0].Textures[0].Bounds.Width, ListSprites[0].Textures[0].Bounds.Height);
            //Vector2 scalesizebtn = new Vector2(SizePanel.X / sizeTexturePanel.X, SizePanel.Y / sizeTexturePanel.Y);

            BtnMenu.SetPosition(GetPositionInScale(BtnMenu.PositionScale));
            BtnMenu.SetSize(BtnMenu.SizeTexture * scalesizebtn);

            BtnEndturn.SetPosition(GetPositionInScale(BtnEndturn.PositionScale));
            BtnEndturn.SetSize(BtnEndturn.SizeTexture * scalesizebtn);

            BtnBuy.SetPosition(GetPositionInScale(BtnBuy.PositionScale));
            BtnBuy.SetSize(BtnBuy.SizeTexture * scalesizebtn);

            BtnMenu.Draw(gameTime, spriteBatch);
            BtnEndturn.Draw(gameTime, spriteBatch);
            BtnBuy.Draw(gameTime, spriteBatch);
        }
        
        public void DrawAvatarCharacter(GameTime gameTime, SpriteBatch spriteBatch, Vector2 scalesizeavt)
        {
            //Vector2 sizeTexturePanel = new Vector2(ListSprites[0].Textures[0].Bounds.Width, ListSprites[0].Textures[0].Bounds.Height);
            //Vector2 scalesizeavt = new Vector2(SizePanel.X / sizeTexturePanel.X, SizePanel.Y / sizeTexturePanel.Y);
            AvatarCurrentCharacter.PositionAvatar = GetPositionInScale(AvatarCurrentCharacter.PositionScale);
            AvatarCurrentCharacter.SizeAvatar = AvatarCurrentCharacter.SizeTexture * scalesizeavt;
            AvatarCurrentCharacter.Draw(gameTime, spriteBatch);


            for (int i = 0; i < ListBuyAvatarCharater.Count; i++)
            {
                ListBuyAvatarCharater[i].PositionAvatar = GetPositionInScale(ListBuyAvatarCharater[i].PositionScale);
                ListBuyAvatarCharater[i].SizeAvatar = ListBuyAvatarCharater[i].SizeTexture * scalesizeavt;
                ListBuyAvatarCharater[i].Draw(gameTime, spriteBatch);
            }
            
        }
        public void DrawStringPanel(SpriteBatch spriteBatch, Vector2 scale)
        {
            Vector2 posnation = GetPositionInScale(this.PositionScaleStringNationName);
            Vector2 postime = GetPositionInScale(this.PositionScaleStringTurnTime);
            Vector2 posmoney = GetPositionInScale(this.PositionScaleStringMoney);
            Vector2 poscharacter = GetPositionInScale(this.PositionScaleStringNumCharacters);
            Vector2 posbuilding = GetPositionInScale(this.PositionScaleStringNumBuildings);
            Color color = new Color();
            switch (NationCurrent)
            {
                case "Red":
                    color = Color.Red;
                    break;
                case "Green":
                    color = Color.Green;
                    break;
                case "Blue":
                    color = Color.Blue;
                    break;
                case "Black":
                    color = Color.Black;
                    break;
            }

            // Draw nation name
            Vector2 FontOrigin = MyFont.FontCourierNew.MeasureString(this.NationCurrent) / 2;
            spriteBatch.DrawString(MyFont.FontCourierNew, NationCurrent, posnation, color,
                                    0, FontOrigin, 1.0f, SpriteEffects.None, 0.5f);

            // Draw time of the turn.
            FontOrigin = MyFont.FontSegoePrint.MeasureString(this.TurnTimeCurrent) / 2;
            spriteBatch.DrawString(MyFont.FontSegoePrint, TurnTimeCurrent, postime, color,
                                    0, FontOrigin, 1.0f * scale.X, SpriteEffects.None, 0.5f);

            // Draw money
            FontOrigin = MyFont.FontSegoePrint.MeasureString(this.MoneyCurrent) / 2;
            spriteBatch.DrawString(MyFont.FontSegoePrint, MoneyCurrent, posmoney, color,
                                    0, FontOrigin, 1.0f * scale.X, SpriteEffects.None, 0.5f);

            // Draw numbers of  buildings
            FontOrigin = MyFont.FontSegoePrint.MeasureString(this.NumBuildingCurrent) / 2;
            spriteBatch.DrawString(MyFont.FontSegoePrint, NumBuildingCurrent, posbuilding, color,
                                    0, FontOrigin, 1.0f * scale.X, SpriteEffects.None, 0.5f);

            // Draw numbers of characters
            FontOrigin = MyFont.FontSegoePrint.MeasureString(NumCharacterCurrent) / 2;
            spriteBatch.DrawString(MyFont.FontSegoePrint, NumCharacterCurrent, poscharacter, color,
                                    0, FontOrigin, 1.0f * scale.X, SpriteEffects.None, 0.5f);

            if (AvatarCurrentCharacter.TextureCurrent != null)
            {
                Vector2 posname = GetPositionInScale(this.PositionScaleCharacterName);
                Vector2 posdamage = GetPositionInScale(this.PositionScaleCharacterDamage);
                Vector2 posdefense = GetPositionInScale(this.PositionScaleCharacterDefense);
                Vector2 poshp = GetPositionInScale(this.PositionScaleCharacterHP);

                // Draw name of character.
                FontOrigin = MyFont.FontSegoePrint.MeasureString(AvatarCurrentCharacter.CharacterName) / 2;
                spriteBatch.DrawString(MyFont.FontSegoePrint, AvatarCurrentCharacter.CharacterName, posname, color,
                                        0, FontOrigin, 1.0f * scale.X, SpriteEffects.None, 0.5f);

                // Draw damage of character.
                FontOrigin = MyFont.FontSegoePrint.MeasureString(AvatarCurrentCharacter.Damage) / 2;
                spriteBatch.DrawString(MyFont.FontSegoePrint, AvatarCurrentCharacter.Damage, posdamage, color,
                                        0, FontOrigin, 1.0f * scale.X, SpriteEffects.None, 0.5f);

                // Draw defense of character.
                FontOrigin = MyFont.FontSegoePrint.MeasureString(AvatarCurrentCharacter.Defense) / 2;
                spriteBatch.DrawString(MyFont.FontSegoePrint, AvatarCurrentCharacter.Defense, posdefense, color,
                                        0, FontOrigin, 1.0f * scale.X, SpriteEffects.None, 0.5f);

                // Draw health point of character.
                FontOrigin = MyFont.FontSegoePrint.MeasureString(AvatarCurrentCharacter.HealthPoints) / 2;
                spriteBatch.DrawString(MyFont.FontSegoePrint, AvatarCurrentCharacter.HealthPoints, poshp, color,
                                        0, FontOrigin, 1.0f * scale.X, SpriteEffects.None, 0.5f);
            }
        }
        public void DrawStringInfoCharacterToBuy(SpriteBatch spriteBatch, Vector2 scale)
        {
            for (int i = 0; i < ListBuyAvatarCharater.Count; i++)
            {
                if (ListBuyAvatarCharater[i].IsSelected)
                {
                    Vector2 posname = GetPositionInScale(this.PositionScaleNameCharacterBuy);
                    Vector2 posprice = GetPositionInScale(this.PositionScalePriceCharacterBuy);
                    Vector2 posdamage = GetPositionInScale(this.PositionScaleDamageCharacterBuy);
                    Vector2 posdefense = GetPositionInScale(this.PositionScaleDefenseCharacterBuy);
                    Vector2 posdistance = GetPositionInScale(this.PositionScaleMaxDistanceCharacterBuy);

                    Color color = new Color();
                    switch (NationCurrent)
                    {
                        case "Red":
                            color = Color.Red;
                            break;
                        case "Green":
                            color = Color.Green;
                            break;
                        case "Blue":
                            color = Color.Blue;
                            break;
                        case "Black":
                            color = Color.Black;
                            break;
                    }

                    // Draw name.
                    Vector2 FontOrigin = MyFont.FontSegoePrint.MeasureString(ListBuyAvatarCharater[i].CharacterName) / 2;
                    spriteBatch.DrawString(MyFont.FontSegoePrint, ListBuyAvatarCharater[i].CharacterName, posname, color,
                                            0, FontOrigin, 1.0f * scale.X, SpriteEffects.None, 0.5f);
                    // Draw price
                    FontOrigin = MyFont.FontSegoePrint.MeasureString(ListBuyAvatarCharater[i].Price) / 2;
                    spriteBatch.DrawString(MyFont.FontSegoePrint, ListBuyAvatarCharater[i].Price, posprice, color,
                                            0, FontOrigin, 1.0f * scale.X, SpriteEffects.None, 0.5f);

                    // Draw damage
                    FontOrigin = MyFont.FontSegoePrint.MeasureString(ListBuyAvatarCharater[i].Damage) / 2;
                    spriteBatch.DrawString(MyFont.FontSegoePrint, ListBuyAvatarCharater[i].Damage, posdamage, color,
                                            0, FontOrigin, 1.0f * scale.X, SpriteEffects.None, 0.5f);

                    // Draw defense
                    FontOrigin = MyFont.FontSegoePrint.MeasureString(ListBuyAvatarCharater[i].Defense) / 2;
                    spriteBatch.DrawString(MyFont.FontSegoePrint, ListBuyAvatarCharater[i].Defense, posdefense, color,
                                            0, FontOrigin, 1.0f * scale.X, SpriteEffects.None, 0.5f);

                    // Draw distance
                    FontOrigin = MyFont.FontSegoePrint.MeasureString(ListBuyAvatarCharater[i].MaxDistance) / 2;
                    spriteBatch.DrawString(MyFont.FontSegoePrint, ListBuyAvatarCharater[i].MaxDistance, posdistance, color,
                                            0, FontOrigin, 1.0f * scale.X, SpriteEffects.None, 0.5f);

                    return;
                }
            }
            
        }
        
    }
}
